package com.sun.dailyprj.zotye.viewmodel;

import android.content.Context;
import android.util.Log;
import android.view.View;

import androidx.databinding.ViewDataBinding;

import com.sun.common.recyclerview.BaseBindingAdapter;
import com.sun.dailyprj.R;
import com.sun.dailyprj.databinding.ActivityDetailListItemBinding;
import com.sun.dailyprj.databinding.ActivityDetailListItemHeadBinding;
import com.sun.dailyprj.zotye.model.UpgradeHeader;
import com.sun.dailyprj.zotye.model.UpgradeInfo;

/*
 * =====================================================================================
 * Summary:
 *
 * File: UpgradeAdapter.java
 * Author: Yanpeng.Sun
 * Create: 2019/9/30 14:45
 * =====================================================================================
 */
public class UpgradeAdapter<M, B extends ViewDataBinding> extends BaseBindingAdapter implements View.OnClickListener{

    private int headCount = 1;//头部个数，后续可以自己拓展

    public UpgradeAdapter(Context context) {
        super(context);
        items.add(new UpgradeInfo("车载监控终端", "V1.3", "V1.4", "1.优化了蓝牙操作界面\n " +
                "2.优化系统卡顿"));
        items.add(new UpgradeInfo("车载大屏", "SW21.29", "SW22.16", "1.优化系统设置-》系统升级界面"));
        items.add(new UpgradeInfo("仪表", "ZT 1.02.7", "ZT 1.02.8", "修复bug"));
        items.add(new UpgradeInfo("仪表", "ZT 1.02.7", "ZT 1.02.8", "修复bug"));
        items.add(new UpgradeInfo("仪表", "ZT 1.02.7", "ZT 1.02.8", "修复bug"));
        items.add(new UpgradeInfo("仪表", "ZT 1.02.7", "ZT 1.02.8", "修复bug"));
        items.add(new UpgradeInfo("仪表", "ZT 1.02.7", "ZT 1.02.8", "修复bug"));
        header.add(new UpgradeHeader("应用", "当前版本", "新版本", "日志"));
    }

    @Override
    protected int getLayoutResId(int viewType) {
        Log.i("syp:", "viewType=" + viewType);
        if(viewType == TYPE_HEADER) {
            return R.layout.activity_detail_list_item_head;
        }
        return R.layout.activity_detail_list_item;
    }

    @Override
    protected void onBindItem(ViewDataBinding binding, Object item, int position) {
        if(binding instanceof ActivityDetailListItemHeadBinding) {
            ((ActivityDetailListItemHeadBinding) binding).setUpgrade((UpgradeHeader) item);
            binding.executePendingBindings();
        } else if(binding instanceof ActivityDetailListItemBinding) {
            ((ActivityDetailListItemBinding) binding).setUpgrade((UpgradeInfo) item);
            binding.executePendingBindings();
//            ((ActivityDetailListItemBinding) binding).ivNotes.setOnClickListener(this);
//            ((ActivityDetailListItemBinding) binding).ivNotes.setTag(position);
        }

    }

    private int getBodySize() {
        return items.size();
    }

    private boolean isHead(int position) {
        return headCount != 0 && position < headCount;
    }

    @Override
    public void onClick(View v) {
        int pos = (int) v.getTag();
    /*    switch(v.getId()) {
            case R.id.iv_notes:
                if(mOnItemClickListener != null) {
                    mOnItemClickListener.onItemClick(v, ViewName.PRACTISE, pos);
                }
                break;
        }*/
    }
}
